#include "Core.h"
#include "GraphicsManager.h"
#include "Font/FontManager.h"
#include "Utils/LanguageManager/LanguageManager.h"
#include "InputManager.h"
#include "Timer\Timer.h"
#include "ActionToInput.h"

CCore::~CCore(void)
{
	DeInit();
}

void CCore::Init(HWND hWnd, const SEngineInitParams& params)
{
	//GraphicsManager
	m_GraphicsManager = new CGraphicsManager();
	assert(m_GraphicsManager);
	m_GraphicsManager->Init(hWnd, params);

	//FontManager
	m_FontManager = new CFontManager();
	assert(m_FontManager);
	m_FontManager->Init(m_GraphicsManager);
	m_FontManager->LoadTTFs(params.m_PathFont);

	//LanguageManager
	m_LanguageManager = new CLanguageManager();
	assert(m_LanguageManager);
	std::vector<std::string>::const_iterator it;
	std::vector<std::string>::const_iterator itEnd = params.m_PathLanguage.cend();
	for (it = params.m_PathLanguage.begin(); it != itEnd; ++it)
	{
			m_LanguageManager->SetXmlFile(*it);
	}
	m_LanguageManager->LoadXMLs();
	m_LanguageManager->SetCurrentLanguage(params.m_Default);

	//InputManager
	m_InputManager = new CInputManager();
	assert(m_InputManager);
	m_InputManager->Init(hWnd, params.m_ScreenResolution, params.m_bExclusiveModeinMouse);
	m_InputManager->Update();

	m_ActionToInput = new CActionToInput();
	assert(m_ActionToInput);
	/*m_ActionToInput->Input(m_InputManager);
	m_ActionToInput->LoadXml();*/
	//Init Sounds:

	//Init PhysX:

}

void CCore::DeInit()
{
	CHECKED_DELETE(m_GraphicsManager);
	CHECKED_DELETE(m_FontManager);
	CHECKED_DELETE(m_LanguageManager);
	CHECKED_DELETE(m_InputManager);
	CHECKED_DELETE(m_ActionToInput);
}

void CCore::Update(float l_DeltaTime)
{
	m_GraphicsManager->Update(l_DeltaTime);
	m_InputManager->Update();
}

void CCore::Render(float l_DeltaTime)
{
	m_GraphicsManager->Render(l_DeltaTime);
}